package top.malaoshi.service.mgr;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.malaoshi.entity.Comment;
import top.malaoshi.mapper.ICommentMapper;
import top.malaoshi.mapper.IGoodsMapper;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class MgrCommentSrvImpl {

    @Resource
    private ICommentMapper dao;

    @Resource
    private IGoodsMapper goodsDao;

    @Transactional
    public boolean add(Comment comment) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        comment.setId(uuid);
        comment.setDelete(0);
        Date date=new Date();
        comment.setCreateTime(date);
        int i=dao.add(comment);

        //更新goods表
        int j=goodsDao.updateCommentNumById(comment.getGoodsId());

        if(i==1 && j==1){
            return true;
        }else{
            return false;
        }
    }

    public List<Comment> mgrQuery(String userId) {
        List<Comment> list=dao.mgrQuery(userId);
        return list;
    }


//    public Result update(String id) {
//        Result res = new Result();
//        dao.update(id);
//        return res;
//    }
//    public Result modifyById(String id){
//        Result res = new Result();
//        dao.modifyById(id);
//        return res;
//    }
}
